/*
 *  crear_nota_request.cpp
 *  Wilson
 *
 *  Created by Sebastian Orfino on 11/15/11.
 *  Copyright 2011 lbs3. All rights reserved.
 *
 */
#include "VCPlugInHeaders.h"

//project includes
#include "crear_nota_request.h"
#include "csxs_facade.h"
#include "xmp_facade.h"                         
#include "pugixml.hpp"

//sdk includes
#include "Event/Event.h"
#include "ILayoutUIUtils.h"
#include "IDocument.h"

#include <sstream>

using namespace eventos;

void crear_nota_request::operator()(const csxs::event::Event * e)
{
	using namespace std;
	using namespace pugi;
	
	//e->data = notacreada.xsd.
	

	istringstream xml(e->data);
	xml_document docu;
	if (docu.load(xml)) {

		xml_node payload_n = docu.child("payload");
		timestamp() = payload_n.child_value("timestamp");
		id_payload() = payload_n.child_value("id");
		creador() = payload_n.child_value("creador");
		mini_ = payload_n.child_value("mini");


		IDocument * frontDoc = Utils<ILayoutUIUtils>()->GetFrontDocument();
		
		xmp::wilson_metadata metadata(::GetUIDRef(frontDoc));
		
		xmp::info_nota_t info = { id_payload(), mini_, creador(), timestamp() };
		metadata.crear_nota(info);
	}
}
